package repertory.android.ericchen.androidrepertory.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * className:
 * author: Ericchen
 * description:
 * date: 2017/3/8 14:08
 * update: 2017/3/8
 * version:
 */
public class MySQLiteDataBaseHelper extends SQLiteOpenHelper{
    //数据库文件名称
    private static final String DATABASE_NAME = "User.db";
    private static final int DATABASE_VERSION = 1;

    //用于创建User表
    public static final String CREATE_USER = "create table User ("
            + "id integer primary key autoincrement, "
            + "username text, "
            + "count integer)";
    public MySQLiteDataBaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(CREATE_USER);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
        sqLiteDatabase.delete("User",null,null);
        onCreate(sqLiteDatabase);
    }
}
